/**
 * 
 */
package verifiers;

import java.awt.Color;

import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JTextPane;


public class PriceVerifier extends InputVerifier  {

	@Override
	public boolean verify(JComponent input) {
		String value = ((JTextPane) input).getText();
		boolean valid = false;
		
		if(value == null || value.trim().equals("")){
			valid = false;
		} else {
			try {
				double v = Double.parseDouble(value);
				if(v>=0){
					valid = true;
				}
				
			}
			catch (NumberFormatException e) {
	
				valid = false;
			}
		}
		

		if(valid){
			input.setBackground(Color.white);
			return true;
		}
		else {
			input.setBackground(Color.red);
			return false;
		}
	}

}
